import Vue from 'vue'
import App from '@/App'
import router from '@/router'                 // api: https://github.com/vuejs/vue-router
import store from '@/store'                   // api: https://github.com/vuejs/vuex
import VueCookie from 'vue-cookie'            // api: https://github.com/alfhen/vue-cookie
// import '@/element-ui'
import '@/icons'                              // api: http://www.iconfont.cn/
// import '@/element-ui-theme'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
// import locale from 'element-ui/lib/locale/lang/en'
import '@/assets/scss/index.scss'
import '@/assets/scss/globle.scss'
import httpRequest from '@/utils/httpRequest'
import {post, get, postForm} from '@/utils/myRequest'
import {isAuth, hasRole, copyText, getNowDate} from '@/utils'
import cloneDeep from 'lodash/cloneDeep'
import api from '@/api/api.js'
import '@/utils/drag.js'
import cityData from '@/utils/cityData.js'
import VueQuillEditor from 'vue-quill-editor'
import pinyin from 'js-pinyin'
import Clipboard from 'clipboard'

import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import '@/assets/iconfont/iconfont.js'
import '@/assets/iconfont/iconfont.css'

// import Vue from 'vue'
// import ZkTable from 'vue-table-with-tree-grid'
// Vue.use(ZkTable)
import ZkTable from 'vue-table-with-tree-grid'
Vue.component('tree-table', ZkTable)

Vue.use(VueQuillEditor)

Vue.use(VueCookie)
Vue.config.productionTip = false

// 非生产环境, 适配mockjs模拟数据                 // api: https://github.com/nuysoft/Mock
if (process.env.NODE_ENV !== 'production') {
  require('@/mock')
}

Vue.use(ElementUI, {
  zhLocale
})

// 挂载全局
Vue.prototype.$http = httpRequest // ajax请求方法
Vue.prototype.getNowDate = getNowDate     // 权限方法
Vue.prototype.isAuth = isAuth     // 权限方法
Vue.prototype.hasRole = hasRole     // 是否有权限
Vue.prototype.copyText = copyText     
Vue.prototype.$api = api     // 接口方法
Vue.prototype.$post = post
Vue.prototype.$get = get
Vue.prototype.$postForm = postForm
Vue.prototype.$pinyin = pinyin
Vue.prototype.$cityData = cityData
Vue.config.devtools = true

// 保存整站vuex本地储存初始状态
window.SITE_CONFIG['storeState'] = cloneDeep(store.state)

Vue.filter('dateTimeFormat', function(originDate){
  if(originDate){
    const dt = new Date(originDate)
    const y = dt.getFullYear()
    const m = (dt.getMonth() + 1 + '').padStart(2, '0')
    const d = (dt.getDate() + '').padStart(2, '0')
    const hh = (dt.getHours()  + '').padStart(2, '0')
    const mm = (dt.getMinutes() + '').padStart(2, '0')
    const ss = (dt.getSeconds() + '').padStart(2, '0')
    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
  }
  return ''

})

Vue.filter('dateFormat', function(originDate){
  if(originDate){
    const dt = new Date(originDate)
    const y = dt.getFullYear()
    const m = (dt.getMonth() + 1 + '').padStart(2, '0')
    const d = (dt.getDate() + '').padStart(2, '0')
    return `${y}-${m}-${d}`
  }
  return ''
})

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})
